<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- For Mobile Devices -->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
        <meta name="generator" content="Doxygen 1.9.1"/>
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <title>libevdev: Main Page</title>
        <!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
        <script type="text/javascript" src="dynsections.js"></script>
        <link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
        <link href="doxygen.css" rel="stylesheet" type="text/css" />
        <link href="bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
<link href="libevdevdoxygen.css" rel="stylesheet" type="text/css"/>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="doxy-boot.js"></script>
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand">libevdev 1.13.0</a>
                </div>
            </div>
        </nav>
        <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
            <div class="content" id="content">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12 panel panel-default" style="padding-bottom: 15px;">
                            <div style="margin-bottom: 15px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">libevdev Documentation</div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>libevdev</b> is a library for handling evdev kernel devices. It abstracts the <a class="el" href="ioctls.html">evdev ioctls</a> through type-safe interfaces and provides functions to change the appearance of the device.</p>
<h1><a class="anchor" id="autotoc_md0"></a>
Development</h1>
<p>The git repository is available here:</p>
<ul>
<li><a href="https://gitlab.freedesktop.org/libevdev/libevdev">https://gitlab.freedesktop.org/libevdev/libevdev</a></li>
</ul>
<p>Development of libevdev is discussed on <a href="http://lists.freedesktop.org/mailman/listinfo/input-tools">input-tools@lists.freedesktop.org</a>. Please submit patches, questions or general comments there.</p>
<h1><a class="anchor" id="autotoc_md1"></a>
Handling events and SYN_DROPPED</h1>
<p>libevdev provides an interface for handling events, including most notably <code>SYN_DROPPED</code> events. <code>SYN_DROPPED</code> events are sent by the kernel when the process does not read events fast enough and the kernel is forced to drop some events. This causes the device to get out of sync with the process' view of it. libevdev handles this by telling the caller that a * <code>SYN_DROPPED</code> has been received and that the state of the device is different to what is to be expected. It then provides the delta between the previous state and the actual state of the device as a set of events. See <a class="el" href="group__events.html#gabb96c864e836c0b98788f4ab771c3a76" title="Get the next event from the device.">libevdev_next_event()</a> and <a class="el" href="syn_dropped.html">SYN_DROPPED handling</a> for more information on how <code>SYN_DROPPED</code> is handled.</p>
<h1><a class="anchor" id="autotoc_md2"></a>
Signal safety</h1>
<p>libevdev is signal-safe for the majority of its operations, i.e. many of its functions are safe to be called from within a signal handler. Check the API documentation to make sure, unless explicitly stated a call is <b>not</b> signal safe.</p>
<h1><a class="anchor" id="autotoc_md3"></a>
Device handling</h1>
<p>A libevdev context is valid for a given file descriptor and its duration. Closing the file descriptor will not destroy the libevdev device but libevdev will not be able to read further events.</p>
<p>libevdev does not attempt duplicate detection. Initializing two libevdev devices for the same fd is valid and behaves the same as for two different devices.</p>
<p>libevdev does not handle the file descriptors directly, it merely uses them. The caller is responsible for opening the file descriptors, setting them to <code>O_NONBLOCK</code> and handling permissions. A caller should drain any events pending on the file descriptor before passing it to libevdev.</p>
<h1><a class="anchor" id="autotoc_md4"></a>
Where does libevdev sit?</h1>
<p>libevdev is essentially a <code>read(2)</code> on steroids for <code>/dev/input/eventX</code> devices. It sits below the process that handles input events, in between the kernel and that process. In the simplest case, e.g. an evtest-like tool the stack would look like this: </p><pre class="fragment"> kernel → libevdev → evtest
</pre><p> For X.Org input modules, the stack would look like this: </p><pre class="fragment"> kernel → libevdev → xf86-input-evdev → X server → X client
</pre><p> For anything using libinput (e.g. most Wayland compositors), the stack the stack would look like this: </p><pre class="fragment"> kernel → libevdev → libinput → Compositor → Wayland client
</pre><p> libevdev does <b>not</b> have knowledge of X clients or Wayland clients, it is too low in the stack.</p>
<h1><a class="anchor" id="autotoc_md5"></a>
Example</h1>
<p>Below is a simple example that shows how libevdev could be used. This example opens a device, checks for relative axes and a left mouse button and if it finds them monitors the device to print the event.</p>
<div class="fragment"><div class="line"><span class="keyword">struct </span>libevdev *dev = NULL;</div>
<div class="line"><span class="keywordtype">int</span> fd;</div>
<div class="line"><span class="keywordtype">int</span> rc = 1;</div>
<div class="line"> </div>
<div class="line">fd = open(<span class="stringliteral">&quot;/dev/input/event0&quot;</span>, O_RDONLY|O_NONBLOCK);</div>
<div class="line">rc = <a class="code" href="group__init.html#ga89bb5bce1c23e293293484b05b12aaf4">libevdev_new_from_fd</a>(fd, &amp;dev);</div>
<div class="line"><span class="keywordflow">if</span> (rc &lt; 0) {</div>
<div class="line">        fprintf(stderr, <span class="stringliteral">&quot;Failed to init libevdev (%s)\n&quot;</span>, strerror(-rc));</div>
<div class="line">        exit(1);</div>
<div class="line">}</div>
<div class="line">printf(<span class="stringliteral">&quot;Input device name: \&quot;%s\&quot;\n&quot;</span>, <a class="code" href="group__bits.html#gaed0328c67b7a78422636d9fe09a73f12">libevdev_get_name</a>(dev));</div>
<div class="line">printf(<span class="stringliteral">&quot;Input device ID: bus %#x vendor %#x product %#x\n&quot;</span>,</div>
<div class="line">       <a class="code" href="group__bits.html#ga9bf55d416401642bad0c435735682308">libevdev_get_id_bustype</a>(dev),</div>
<div class="line">       <a class="code" href="group__bits.html#ga08891c3285da5b8d26769c9a34f063f3">libevdev_get_id_vendor</a>(dev),</div>
<div class="line">       <a class="code" href="group__bits.html#ga1dc66cfef646878d58be72f8902a6bac">libevdev_get_id_product</a>(dev));</div>
<div class="line"><span class="keywordflow">if</span> (!<a class="code" href="group__bits.html#ga398bef155fa4a0cfb832de30723ebd14">libevdev_has_event_type</a>(dev, EV_REL) ||</div>
<div class="line">    !<a class="code" href="group__bits.html#gab2ab9dad417f33daa79fa0c3d682df0b">libevdev_has_event_code</a>(dev, EV_KEY, BTN_LEFT)) {</div>
<div class="line">        printf(<span class="stringliteral">&quot;This device does not look like a mouse\n&quot;</span>);</div>
<div class="line">        exit(1);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordflow">do</span> {</div>
<div class="line">        <span class="keyword">struct </span>input_event ev;</div>
<div class="line">        rc = <a class="code" href="group__events.html#gabb96c864e836c0b98788f4ab771c3a76">libevdev_next_event</a>(dev, <a class="code" href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9ac0d6ee19551eecf76f1ede4f36252418">LIBEVDEV_READ_FLAG_NORMAL</a>, &amp;ev);</div>
<div class="line">        <span class="keywordflow">if</span> (rc == 0)</div>
<div class="line">                printf(<span class="stringliteral">&quot;Event: %s %s %d\n&quot;</span>,</div>
<div class="line">                       <a class="code" href="group__misc.html#gac99720fd926bf288764f9a81bf37ed09">libevdev_event_type_get_name</a>(ev.type),</div>
<div class="line">                       <a class="code" href="group__misc.html#gab407b3c2caaae502859c28460cad17bb">libevdev_event_code_get_name</a>(ev.type, ev.code),</div>
<div class="line">                       ev.value);</div>
<div class="line">} <span class="keywordflow">while</span> (rc == 1 || rc == 0 || rc == -EAGAIN);</div>
<div class="ttc" id="agroup__bits_html_ga08891c3285da5b8d26769c9a34f063f3"><div class="ttname"><a href="group__bits.html#ga08891c3285da5b8d26769c9a34f063f3">libevdev_get_id_vendor</a></div><div class="ttdeci">int libevdev_get_id_vendor(const struct libevdev *dev)</div></div>
<div class="ttc" id="agroup__bits_html_ga1dc66cfef646878d58be72f8902a6bac"><div class="ttname"><a href="group__bits.html#ga1dc66cfef646878d58be72f8902a6bac">libevdev_get_id_product</a></div><div class="ttdeci">int libevdev_get_id_product(const struct libevdev *dev)</div></div>
<div class="ttc" id="agroup__bits_html_ga398bef155fa4a0cfb832de30723ebd14"><div class="ttname"><a href="group__bits.html#ga398bef155fa4a0cfb832de30723ebd14">libevdev_has_event_type</a></div><div class="ttdeci">int libevdev_has_event_type(const struct libevdev *dev, unsigned int type)</div></div>
<div class="ttc" id="agroup__bits_html_ga9bf55d416401642bad0c435735682308"><div class="ttname"><a href="group__bits.html#ga9bf55d416401642bad0c435735682308">libevdev_get_id_bustype</a></div><div class="ttdeci">int libevdev_get_id_bustype(const struct libevdev *dev)</div></div>
<div class="ttc" id="agroup__bits_html_gab2ab9dad417f33daa79fa0c3d682df0b"><div class="ttname"><a href="group__bits.html#gab2ab9dad417f33daa79fa0c3d682df0b">libevdev_has_event_code</a></div><div class="ttdeci">int libevdev_has_event_code(const struct libevdev *dev, unsigned int type, unsigned int code)</div></div>
<div class="ttc" id="agroup__bits_html_gaed0328c67b7a78422636d9fe09a73f12"><div class="ttname"><a href="group__bits.html#gaed0328c67b7a78422636d9fe09a73f12">libevdev_get_name</a></div><div class="ttdeci">const char * libevdev_get_name(const struct libevdev *dev)</div><div class="ttdoc">Retrieve the device's name, either as set by the caller or as read from the kernel.</div></div>
<div class="ttc" id="agroup__events_html_gabb96c864e836c0b98788f4ab771c3a76"><div class="ttname"><a href="group__events.html#gabb96c864e836c0b98788f4ab771c3a76">libevdev_next_event</a></div><div class="ttdeci">int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event *ev)</div><div class="ttdoc">Get the next event from the device.</div></div>
<div class="ttc" id="agroup__events_html_gga56c288d9f2e4c1632986c4e218c494e9ac0d6ee19551eecf76f1ede4f36252418"><div class="ttname"><a href="group__events.html#gga56c288d9f2e4c1632986c4e218c494e9ac0d6ee19551eecf76f1ede4f36252418">LIBEVDEV_READ_FLAG_NORMAL</a></div><div class="ttdeci">@ LIBEVDEV_READ_FLAG_NORMAL</div><div class="ttdoc">Process data in normal mode.</div><div class="ttdef"><b>Definition:</b> libevdev.h:762</div></div>
<div class="ttc" id="agroup__init_html_ga89bb5bce1c23e293293484b05b12aaf4"><div class="ttname"><a href="group__init.html#ga89bb5bce1c23e293293484b05b12aaf4">libevdev_new_from_fd</a></div><div class="ttdeci">int libevdev_new_from_fd(int fd, struct libevdev **dev)</div><div class="ttdoc">Initialize a new libevdev device from the given fd.</div></div>
<div class="ttc" id="agroup__misc_html_gab407b3c2caaae502859c28460cad17bb"><div class="ttname"><a href="group__misc.html#gab407b3c2caaae502859c28460cad17bb">libevdev_event_code_get_name</a></div><div class="ttdeci">const char * libevdev_event_code_get_name(unsigned int type, unsigned int code)</div></div>
<div class="ttc" id="agroup__misc_html_gac99720fd926bf288764f9a81bf37ed09"><div class="ttname"><a href="group__misc.html#gac99720fd926bf288764f9a81bf37ed09">libevdev_event_type_get_name</a></div><div class="ttdeci">const char * libevdev_event_type_get_name(unsigned int type)</div></div>
</div><!-- fragment --><p>A more complete example is available with the libevdev-events tool here: <a href="https://gitlab.freedesktop.org/libevdev/libevdev/blob/master/tools/libevdev-events.c">https://gitlab.freedesktop.org/libevdev/libevdev/blob/master/tools/libevdev-events.c</a></p>
<h1><a class="anchor" id="autotoc_md6"></a>
Backwards compatibility with older kernel</h1>
<p>libevdev attempts to build and run correctly on a number of kernel versions. If features required are not available, libevdev attempts to work around them in the most reasonable way. For more details see <a class="el" href="backwardscompatibility.html">Compatibility and Behavior across kernel versions</a>.</p>
<h1><a class="anchor" id="autotoc_md7"></a>
License information</h1>
<p>libevdev is licensed under the <a href="http://cgit.freedesktop.org/libevdev/tree/COPYING">X11 license</a>.</p>
<h1><a class="anchor" id="autotoc_md8"></a>
Bindings</h1>
<ul>
<li>Python: <a href="https://gitlab.freedesktop.org/libevdev/python-libevdev">https://gitlab.freedesktop.org/libevdev/python-libevdev</a></li>
<li>Haskell: <a href="http://hackage.haskell.org/package/evdev">http://hackage.haskell.org/package/evdev</a></li>
<li>Rust: <a href="https://crates.io/crates/evdev-rs">https://crates.io/crates/evdev-rs</a></li>
</ul>
<h1><a class="anchor" id="autotoc_md9"></a>
Reporting bugs</h1>
<p>Please report bugs in the freedesktop.org GitLab instance: <a href="https://gitlab.freedesktop.org/libevdev/libevdev/issues/">https://gitlab.freedesktop.org/libevdev/libevdev/issues/</a> </p>
</div></div><!-- PageDoc -->
</div><!-- contents -->
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.9.1
</small></address>
</body>
</html>
